package org.kjk.mail;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONObject;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

public class GMailSubjectJsonController extends AbstractController {
	private GMail gmail;
	private String id;
	private String pass;

	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		id = (String) request.getSession().getAttribute("id");
		pass = (String) request.getSession().getAttribute("pass");
		if (id == null || id.length() == 0) {
//			return new ModelAndView("/mail/gmailLogin.jsp");
		}
		id = "kjkjjang@gmail.com";
		pass = "rlawlsry85";
		gmail.setAccountDetails(id, pass);
		System.out.println("Page Loading");
		JSONObject subject = gmail.getJsonSubject();
		if (subject == null) {
			return new ModelAndView("/mail/gmailLogin.jsp");
		}
		System.out.println("page load success");
		response.getWriter().println(subject);
		return null;
	}

	public void setGmail(GMail gmail) {
		this.gmail = gmail;
	}

}
